package com.imooc.test;

import com.imooc.test.AsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

@RestController
public class AsyncController {

    @Autowired
    private AsyncService asyncService;

    @GetMapping("/open")
    public String something() throws ExecutionException, InterruptedException {
        int count = 10;
        int a=0;

          asyncService.doSomething("index = " + 1);
          if(a==0){
              asyncService.doSomething("index = " + 2);
          }
        asyncService.doSomething("index = " + 3);





        return "success";
//        CompletableFuture<String> createOrder = asyncService.doSomething1("create order");
//        CompletableFuture<String> reduceAccount = asyncService.doSomething2("reduce account");
//        CompletableFuture<String> saveLog = asyncService.doSomething3("save log");
//
//        // 等待所有任务都执行完
//        CompletableFuture.allOf(createOrder, reduceAccount, saveLog).join();
//        // 获取每个任务的返回结果
//
//        String result = createOrder.get() + reduceAccount.get() + saveLog.get();
//        System.out.println(result);
//        return result;
    }
}
